[-methods {haplotypes} | R Documentation |
Extract or replace parts of an object of class Dna
Description
Operators acting on sequence matrix to extract or replace parts.
Usage
## S4 method for signature 'Dna'
x[i, j,..., drop = FALSE]
## S4 replacement method for signature 'Dna'
x[i, j]<- value
Arguments
x |
an object of class |
i , j |
elements to extract or replace. |
... |
Additional arguments. In this context, ... is used primarily for as.matrix, which is a boolean. If as.matrix is TRUE (default), the function returns a matrix. If drop is also TRUE, and the subset has either a single row or column, the function will return a vector instead. If as.matrix is FALSE, the function returns an object of class |
drop |
boolean; if TRUE and a single row or column is selected, the function returns a vector instead of a matrix. This is only applicable when as.matrix is TRUE. |
value |
a character vector or a character matrix. |
Details
The S4 method dispatch mechanism matches arguments based on those specified in the signature of the corresponding generic function. However, for some generics that include '...' in their signature, additional arguments can be incorporated in specific methods. Notably, the '[' function does not follow this pattern and restricts the arguments to those defined in its signature. In this context, the 'as.matrix' argument is not in the signature of the generic '[', so it is included within '...'. Then, within the body of the function, we check whether 'as.matrix' has been provided in the actual arguments when the function is called. If 'as.matrix' is not specified, the function defaults to 'TRUE', preserving the behavior of previous versions of the method.
Value
returns an object of class matrix, vector or Dna
.
Methods
signature(x = "Dna", i = "ANY", j = "ANY", drop = "ANY")
Author(s)
Caner Aktas, caktas.aca@gmail.com
See Also
Examples
data("dna.obj")
x<-dna.obj
## Extract parts.
# a matrix object
x[1:2,1:3]
# a Dna object, as.dna(x[1:2,1:3]) gives the same result
x[1:2,1:3,as.matrix=FALSE]
# a vector object
x[1,1:4,drop=TRUE]
## Replace parts.
#"G" "C"
x[1,1:2]
x[1,1:2]<-c("A","T")
x[1,1:2]